<template>
  <el-container>
    <el-header>
      <div>电商后台管理系统</div>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu default-active="2" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff"
          active-text-color="#ffd04b" router>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-s-custom"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item index="/userList">
              <i class="el-icon-menu"></i>
              <span slot="title">用户列表</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-shopping-bag-1"></i>
              <span>商品管理</span>
            </template>
            <el-menu-item index="2-1">
              <i class="el-icon-menu"></i>
              <span slot="title">商品列表</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-notebook-2"></i>
              <span>订单管理</span>
            </template>
            <el-menu-item index="3-1">
              <i class="el-icon-menu"></i>
              <span slot="title">订单列表</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default {
    name: 'Home',
    data() {
      return {
        // 左侧菜单数据
        menuList: [],
        isCollapse: false, // 是否折叠属性
        activePath: ''
      }
    },
    created() {
      // this.getMenuList()
      this.activePath = window.sessionStorage.getItem('activePath')
    },
    methods: {
      logout() {
        window.sessionStorage.clear()
        this.$router.push('/login')
      },
      // 获取所有的菜单
      async getMenuList() {
        const {
          data: res
        } = await this.$http.get('/menus')
        if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
        this.$message.success(res.meta.msg)
        res.data.unshift(this.welcome)
        this.menuList = res.data
        console.log(res, 'menus')
      },
      saveActivePath(activePath) {
        window.sessionStorage.setItem('activePath', activePath)
        this.activePath = activePath
        // console.log(this.$route.path)
      }
    }
  }
</script>

<style scoped>
  .el-container {
    height: 100%;
  }

  .el-header {
    background-color: rgb(84, 92, 100);
  }

  .el-header div {
    margin: 15px;
    color: rgb(255, 255, 255);
    font-size: 20px;
  }

  .el-aside {
    border-top: #00aa7f solid 1px;
    background-color: rgb(84, 92, 100);
  }

  .el-aside .el-menu {
    background-color: rgb(84, 92, 100);
    border-right: none;
  }
</style>
